package com.siyoumi.app.modules.user.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.siyoumi.app.entity.SysUser;
import com.siyoumi.app.modules.user.service.SvcSysUser;
import com.siyoumi.component.XBean;
import com.siyoumi.component.http.InputData;
import com.siyoumi.controller.AdminApiController;
import com.siyoumi.mybatispuls.JoinWrapperPlus;
import com.siyoumi.util.XReturn;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/xadmin/user/user__list")
public class user__list
        extends AdminApiController {
    @GetMapping()
    public XReturn index() {
        setPageTitle("用户列表");

        InputData inputData = InputData.fromRequest();

        JoinWrapperPlus<SysUser> query = SvcSysUser.getBean().listQuery(inputData);
        query.orderByAsc("user_id");
        IPage<SysUser> page = new Page<>(getPageIndex(), getPageSize());

        IPage<Map<String, Object>> pageData = SvcSysUser.getApp().getMaps(page, query);
        //数量
        long count = pageData.getTotal();
        //列表数据处理
        List<Map<String, Object>> list = pageData.getRecords();
        for (Map<String, Object> item : list) {
            SysUser entity = XBean.fromMap(item, SysUser.class);

            item.put("id", entity.getKey());
        }

        getR().setData("list", list);
        getR().setData("count", count);

        return getR();
    }
}

